<?php

namespace app\api\controller\v1;

use \app\common\controller\ApiCommon;
use app\common\model\Assistant;

class Assistants extends ApiCommon
{
    protected $modelName = 'Assistant';

    /**
     * RESTful 索引接口
     *
     * @return void
     */
    public function index()
    {
        $this->checkPermission(10);
        return parent::_index();
    }

    /**
     * RESTful 保存单个数据
     *
     * @return void
     */
    public function save()
    {
        $this->checkPermission(2);
        return parent::_save();
    }

    /**
     * RESTFul更新单个数据
     *
     * @return void
     */
    public function update($id)
    {
        $this->checkPermission(2);
        return parent::_update($id);
    }

    /**
     * 删除单个数据
     *
     * @param [type] $id
     * @return void
     */
    public function delete($id)
    {
        $this->checkPermission(2);
        return parent::_delete($id);
    }

    /**
     * 删除多个数据
     *
     * @param [type] $ids
     * @return void
     */
    public function deletes($ids)
    {
        $this->checkPermission(2);
        return parent::_deletes($ids);
    }

    /**
     * 解除微信绑定
     *
     * @param mixed $id
     * @return void
     */
    public function unbind()
    {
        $id=$this->request->param('id');
        if (!$id){
            return json_response([],STATUS_INVALD_PARAM,"必须传入助理ID");
        }
        $this->checkPermission(2);
        if (!($assistant = Assistant::get($id))) {
            return json_response([], STATUS_FAIL, '助理信息不存在');
        }
        $assistant->setAttr('openid',null);
        $assistant->save();
        return json_response([]);
    }
}
